<?php

namespace Admin\Controller;


/** 
 * 应用管理
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

class AppVersionController extends BaseManageController 
{
	protected $modelName = 'AppVersion';		// 必须定义
	protected $is_del 	 = false; 				// 是否真实删除

	protected function _initialize()
	{
		parent::_initialize();
		$model = &$this->model;
		$this->text_map['type'] = C('PHONE_OS');
		$this->assign('options', $this->text_map);
	}

	public function _before_index()
	{
		$this->where = array();
		if (I('status') !== '')
		{
			$this->where['status'] = I('status', 0, 'intval');
		}
	}
	
	public function config($type = 'pc')
	{
		$list = [
			'pc' => [
				'PC_TOOL_XML' => 'PC工具配置(XML)',
				'TOOL_UPDATE_EXE' => '工具update.exe地址',
				'TOOL_UPDATE_EXE_BIGFOOT' => '工具update.exe地址-大脚版',
				'TOOL_UPDATE_INFO' => '工具更新文档',
				'TOOL_UPDATE_INFO_BIGFOOT' => '工具更新文档-大脚版',
				'TOOL_UPDATE_INFO_UPLOADER' => '工具更新文档-上传工具',
			],
		];
		if (!in_array($type, array_keys($list))) {
			$this->error('参数错误');
		}
		$model = M('Config');
		$names = array_keys($list[$type]);

		if (IS_POST) {
			$data = I('');
			if (!$data) {
				$this->error('参数错误');
				return;
			}
			foreach ($data as $name => $value) {
				if (in_array($name, $names)) {
                	$model->where(['name' => $name])->setField('value', $value);
				}
	        }
	        $this->success('保存成功');
		}

		$data = $model->where(['name' => ['in', $names]])->field('name,title,value,remark')->select();
		$this->data = $data ?: [];
		$this->type = $type;
		$this->display();
	}
}